/*
         <div id="mybox">
            <div id="mybox_aplat"></div>
            <div id="mybox_loader"></div>
            <div id="mybox_conteneur">
                <div id="mybox_relative">
                    <div id="mybox_close"></div>
                    <div id="mybox_contenu">
                        <img src="img/1.jpg" alt="Img"/>
                    </div>
                </div>
            </div>
        </div>
 */
$(document).ready(function(){
    mybox.init("myBox");
    mybox.init("cmyBox");
    mybox.init("bmyBox");
    mybox.init("mmyBox");
    mybox.init("pmyBox");
    mybox.init("details");
    
    //alert("ee");
});

mybox={

    init: function(rel){
        mybox.opacite=0.70;
        mybox.duree=1000;
        mybox.hauteur=400;
        mybox.largeur=800;
        mybox.rel=rel;
        $("a[rel='"+mybox.rel+"']").click(function(){
            //return false;
            mybox.lien=$(this).attr("href");
            mybox.open(mybox.lien);
            return false;
        });
    },

    open: function(lien){
        mybox.lien = lien;
            $("body").append('<div id="mybox"><div id="mybox_aplat"/><div id="mybox_loader"/><div id="mybox_conteneur"><div id="mybox_relative"><div id="mybox_close"/><div id="mybox_contenu"></div></div></div></div>');
            $("#mybox_loader").hide().fadeIn();
            $('#mybox_aplat').hide().fadeTo(500,mybox.opacite);
            
            $.post(mybox.lien,function(data){mybox.load(data);});
            $("#mybox_aplat").click(function(){mybox.close();});
            $("#mybox_close").click(function(){mybox.close();});            
        },

    load: function(data){
        //alert(data.length);
        if(data.length>0){
             //alert("e");
            mybox.anim(data);
        }
        },
    anim: function(data){
        $("#mybox_conteneur").show();
        
        $("#mybox_contenu").append(data);
       // $("#mybox_contenu img").hide();
 
        $("#mybox_close").hide();
//        $("#mybox_contenu").animate({width:mybox.largeur},mybox.duree/2).animate({height:mybox.hauteur},mybox.duree/2,"linear",function(){
//                    $("#mybox_close").fadeIn();
//                    $("#mybox_loader").hide();
//        //$("#mybox_contenu img").fadeIn();
//        });
        $("#mybox_contenu").fadeIn('fast',function(){
                    $("#mybox_close").fadeIn();
                    $("#mybox_loader").hide();
        //$("#mybox_contenu img").fadeIn();
        });
  
    },
    close: function(){

        $("#mybox").fadeOut(500,function(){
           $("#mybox").remove();
        });

    },

    windowH: function(){
        if(window.innerHeight) return window.innerHeight ;
        else{return $(window).height();}
    },

    windowW: function(){
        if(window.innerWidth) return window.innerWidth ;
        else{return $(window).width();}
    },

    scrollY: function(){
        scrOfY=0;
        if(typeof(window.pageYOffset)=='number'){
            scrOfY=window.pageYOffset;
        }
        else if(document.body && (document.body.scrollTop)){
            scrOfY=document.body.scrollTop;
        }
        else if(document.documentElement && (document.documentElement.scrollTop)){
            scrOfY=document.documentElement.scrollTop;
        }
        return scrOfY;
    }

    }